<template>
  <div class="index-daily sub-margin">
    <div class="content">
      <div class="search-box">
        <el-menu
          size="small"
          :default-active="activeCode"
          class="search-menu-box"
          mode="horizontal"
          @select="onMenuClick">
          <el-menu-item v-for="item in menuInfo" :key="item.status" :index="item.status">
            {{ item.label }}
          </el-menu-item>
        </el-menu>
      </div>
      <div class="table-con">
        <div class="right-con">
          <GoodsUse v-if="activeCode === '0'" />
          <Repairs v-if="activeCode === '1'" />
          <ExpenseAccount v-if="activeCode === '2'" />
          <WeekendDuty v-if="activeCode === '3'" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import GoodsUse from './goodsUse' // 物品领用
import Repairs from './repairs' // 报修维修
import ExpenseAccount from './expenseAccount' // 出差报销
import WeekendDuty from './weekendDuty' // 周末值班
export default {
  name: 'PSKH_DAILY_MANAGE',
  components: { WeekendDuty, ExpenseAccount, GoodsUse, Repairs },
  props: {
    chooseTab: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      menuInfo: [
        {
          label: '物品领用',
          status: '0',
        },
        {
          label: '报修维修',
          status: '1',
        },
        {
          label: '出差报销',
          status: '2',
        },
      ],
      activeCode: '0',
    }
  },
  watch: {},
  computed: {
    ...mapGetters('role', [
      'isOtherRole',
      'isNormalRole',
      'isOrgRole',
      'isPartRole',
      'isApplyRole',
      'isRepairRole',
      'isReimburseRole',
      'isBusinessRole',
      'isWeekendRole',
    ]),
  },
  created() {
    this.dealAudit()
  },
  mounted() {},
  methods: {
    onMenuClick(code) {
      this.activeCode = code
    },
    dealAudit() {
      const menu = []
      if (this.isOtherRole || this.isNormalRole || this.isOrgRole || this.isApplyRole) {
        menu.push({
          label: '物品领用',
          status: '0',
        })
      }
      if (this.isOtherRole || this.isNormalRole || this.isOrgRole || this.isRepairRole) {
        menu.push({
          label: '报修维修',
          status: '1',
        })
      }
      if (
        this.isOtherRole ||
        this.isNormalRole ||
        this.isOrgRole ||
        this.isPartRole ||
        this.isBusinessRole ||
        this.isReimburseRole
      ) {
        menu.push({
          label: '出差报销',
          status: '2',
        })
      }
      if (this.isOrgRole || this.isWeekendRole) {
        menu.push({
          label: '周末值班',
          status: '3',
        })
      }
      this.menuInfo = Array.from(new Set(menu.map(JSON.stringify))).map(JSON.parse)
      // 数组排序
      this.menuInfo.sort((a, b) => {
        return a.status - b.status
      })
      this.activeCode = this.menuInfo[0].status
    },
  },
}
</script>
<style lang="scss" scoped>
@import '@styles/layout.scss';
.index-daily {
  height: 100%;
  .content {
    // height: calc(100% - 78px);
    height: calc(100% - 8px);
    padding-bottom: 20px;
    display: flex;
    flex-direction: column;
    position: relative;
    .search-box {
      width: 100%;
      .el-menu {
        .is-active {
          font-weight: bold;
          font-size: 16px;
        }
      }
    }
    .table-con {
      flex: 1;
      display: flex;
      align-items: stretch;
      // padding: 20px 0;
      height: calc(100% - 50px);
      .left-con {
        width: 300px;
        height: 100%;
        overflow: auto;
        position: relative;
        border-right: 1px solid #e4eaf0;
      }

      .right-con {
        flex: 1;
        width: 100%;
        // max-width: 1200px;
        margin: 0 auto;
        // margin-left: 20px;
        position: relative;
        display: flex;
        flex-direction: column;
      }
    }
  }
}
</style>
